<?php

namespace App\Http\Controllers\admin;

use App\Http\Controllers\Controller;
use App\Models\Labor;
use App\Models\LaborBlack;
use App\Models\LaborCompany;
use App\Models\LaborCompanyContract;
use App\Models\LaborExit;
use App\Models\LaborTeam;
use App\Models\LaborTeamContract;
use App\Models\Project;
use Illuminate\Http\Request;

class DashboardController extends Controller
{

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function console(Request $request)
    {

        $projects = [];
        $company = [];
        $team = [];
        $labor = [];
        $date = Date('Y-m-d',time());
        $projects['count'] = Project::where('company_id',$request->company_id)->count();
        $projects['amounts'] = Project::where('company_id',$request->company_id)->sum('price');
        $projects['end'] = Project::whereDate('end_date','<',$date)->where('company_id',$request->company_id)->count();
        $projects['afoot'] = Project::whereDate('end_date','>',$date)->where('company_id',$request->company_id)->count();

        $company['count'] = LaborCompany::where('company_id',$request->company_id)->count();
        $company['amounts'] = LaborCompanyContract::where('company_id',$request->company_id)->sum('price');
        $company['contracts'] = LaborCompanyContract::where('company_id',$request->company_id)->count();

        $team['count'] = LaborTeam::where('company_id',$request->company_id)->count();
        $team['amounts'] = LaborTeamContract::where('company_id',$request->company_id)->sum('price');
        $team['contracts'] = LaborTeamContract::where('company_id',$request->company_id)->count();

        $labor['count'] = Labor::where('company_id',$request->company_id)->count();
        $labor['exit'] = LaborExit::where('company_id',$request->company_id)->count();
        $labor['black'] = LaborBlack::where('company_id',$request->company_id)->count();
        return response()->json(['code' => 200, 'message' => '操作成功','projects'=>$projects,'company'=>$company,'team'=>$team,'labor'=>$labor]);
    }
}
